package com.fourth.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fourth.dao.UBbusinessDao;
import com.fourth.dao.UBcommodityManagerDao;
import com.fourth.service.UBbusinessService;
import com.fourth.service.UBcommodityManagerService;
import com.fourth.vo.CommodityManageVo;
import com.github.pagehelper.PageHelper;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Goods;
import com.ljx.security.util.WebUtils;
import com.ljx.utils.JwtUtil;
import com.ljx.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2023/3/4 16:29
 * @Version 1.0
 */
@Service
public class UBcommodityManagerServiceImpl extends ServiceImpl<UBcommodityManagerDao, Goods> implements UBcommodityManagerService {
	@Autowired(required = false)
	private UBcommodityManagerDao uBcommodityManagerDao;

	@Autowired
	private UBbusinessService uBbusinessService;

	@Autowired(required = false)
	private UBbusinessDao uBbusinessDao;
	@Override
	public Result selectAllGoodsInfoByBusinessId(Integer currentPage, Integer pageSize, Goods goods) {

		Page<CommodityManageVo> page = new Page<>(currentPage,pageSize);

		HttpServletRequest request = WebUtils.getRequest();
		String token = request.getHeader("token");
		Map<String, Object> map = JwtUtil.getTokenChaim(token);
		String username = (String) map.get("username");


		BusinessInfo businessInfo=uBbusinessDao.selectBusinessBytelephone(username);

		goods.setBid(businessInfo.getId());
		System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
		System.out.println(goods);
		page = uBcommodityManagerDao.selectAllGoodsInfoByBusinessId(page,goods);
		if(page!=null){
			return new Result(2000,"查询成功",page);
		}
		return new Result(2000,"查询失败");
	}
}
